# Reference: <https://postmarketos.org/devicepkg>
# Maintainer: Patriot-06 <mbmc172@gmail.com>

pkgname=device-realme-x3
pkgdesc="Realme X3"
pkgver=1
pkgrel=0
url="https://postmarketos.org"
license="MIT"
arch="aarch64"
options="!check !archcheck"
depends="
	postmarketos-base
	mkbootimg
	linux-realme-x3
	mesa-vulkan-freedreno
	swclock-offset
"
makedepends="devicepkg-dev"
source="
	alsa-ucm-conf/HiFi.conf
	alsa-ucm-conf/x3.conf
	deviceinfo
	30-gpu-firmware.files
	51-qcom-sm8150.lua
	modules-initfs
"

subpackages="
	$pkgname-nonfree-firmware:nonfree_firmware
	$pkgname-alsa_ucm_conf
	$pkgname-wireplumber
"

build() {
	devicepkg_build $startdir $pkgname
}

package() {
	devicepkg_package $startdir $pkgname
}

nonfree_firmware() {
	pkgdesc="Firmware for GPU, Touchscreen, Audio, Bluetooth, WiFi, etc."
	depends="
		firmware-realme-x3
		msm-modem
		pd-mapper
		pd-mapper-openrc
		tqftpserv
		tqftpserv-openrc
		bootmac
		alsa-utils
		"
	install="$subpkgname.post-install"
	mkdir "$subpkgdir"

	install -Dm644 "$srcdir/30-gpu-firmware.files" \
		 "$subpkgdir/usr/share/mkinitfs/files/30-gpu-firmware.files"
}

alsa_ucm_conf() {
	install -Dm644 "$srcdir/HiFi.conf" \
		"$subpkgdir/usr/share/alsa/ucm2/Realme/x3/HiFi.conf"

	install -Dm644 "$srcdir/x3.conf" \
		"$subpkgdir/usr/share/alsa/ucm2/Realme/x3/x3.conf"

	mkdir -p "$subpkgdir/usr/share/alsa/ucm2/conf.d/sdm845"
	ln -s ../../Realme/x3/x3.conf \
		"$subpkgdir/usr/share/alsa/ucm2/conf.d/sdm845/Realme X3.conf"
}

wireplumber() {
	install -Dm644 "$srcdir/51-qcom-sm8150.lua" \
		-t "$subpkgdir/usr/share/wireplumber/main.lua.d"
}

sha512sums="
da5509da4b7f0dbf5e2c95375b334a750cef620f8ea77c17c8dde611134bdf474b4e10723f6d656b42843a727e395d352dd0578f1317fcbdf623f4533273fb49  HiFi.conf
28d8dadac648f007d6e554684200bb1c0fb699a472e8459802691bbbadd67458626969d3d418ae145b94bedb3e83d73e8403206c0b4b509a6d3c541b6b733a7a  x3.conf
acf570712aa2a4135661d1c8933be76924f1ff9962db94e072a9dfb694fea040aa91d8f03241742d193ea229091323348c3b82408ffddb168e8b54695353b4b4  deviceinfo
281ddbbd0cc49f54debed63d4531b5b3154b7c1ff9b5482d4b5b8cf655ddb9972f2a21b889db0bde5b9607dd298c9ed9b61c9772f1d0544a5e103da73d4dcf4f  30-gpu-firmware.files
d97601fd5bd36c5710c9a122e400cdd0aecf37df7088bfef4490aef2356f15533cdf70e47e3a270cd77d5384ac1fcdc9c6ea46e314c3b88db26bfc8d86fdadce  51-qcom-sm8150.lua
dbf6f3280cda66914be3215d771105b2994fc2e76c69d461c63ddbb914fe7882432a4d8c8a2590288c660ae4a834c2ddf0f7282a87c87c965631574db38c5a1c  modules-initfs
"
